FROM golang:1.19-alpine AS builder

WORKDIR /build

# 复制go.mod和go.sum文件
COPY go.mod ./
COPY go.sum ./

# 下载依赖
RUN go mod download

# 复制源代码
COPY . .

# 构建应用
RUN CGO_ENABLED=0 GOOS=linux go build -a -o app .

# 最终阶段
FROM alpine:latest

WORKDIR /app

# 从构建阶段复制二进制文件
COPY --from=builder /build/app .

# 创建配置目录
RUN mkdir -p /app/config

# 暴露端口
EXPOSE 8080

# 运行应用
CMD ["./app"] 